# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=keystone
pkgver=0.9.1
pkgrel=4
pkgdesc="Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings"
url="http://www.keystone-engine.org"
arch="all"
license="custom"
depends=""
makedepends="cmake python3-dev"
install=""
subpackages="$pkgname-dev $pkgname-doc $pkgname-python"
source="$pkgname-$pkgver.tar.gz::https://github.com/keystone-engine/$pkgname/archive/$pkgver.tar.gz
	none-build-type.patch"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"
	mkdir -p build-shared && cd build-shared
	cmake -DCMAKE_INSTALL_PREFIX=/usr \
      -DCMAKE_BUILD_TYPE=None \
      -DBUILD_SHARED_LIBS=ON \
      -G "Unix Makefiles" ..
	cd ..
	make -C build-shared || return 1
}

package() {
	cd "$builddir"
	make -C build-shared DESTDIR="$pkgdir" install
}

doc() {
	pkgdesc="Documentation and samples for $pkgname"
	arch="noarch"
	cd "$builddir"
	mkdir -p "${subpkgdir}/usr/share/doc/${pkgname}"
	mv samples "${subpkgdir}/usr/share/doc/${pkgname}"
}

python() {
	pkgdesc="$pkgname python3 bindings"
	depends="python3 keystone"
	arch="noarch"
	cd "$builddir"/bindings/python
	python3 setup.py build
	python3 setup.py install --prefix=/usr --root="$subpkgdir"
}

sha512sums="3bd9c3793d5862a0a8628b52da381625e62445f661dbd5ed715723e7d9db01ce3f9586e5ca0a5cc71e8ceb6c912050f5c28e3ccd540e72c8abcfd2f0d1bbae17  keystone-0.9.1.tar.gz
0a101a1398eec32e7cb2e5e201d8f822ec44916e7c40ed59caf89482102b536e1ec9a23bc9321bc14a4ac56db11669b4c7aa5b297942af25cf8ccf21d9483037  none-build-type.patch"
